function onMapsClick(param)
{
     if (!geoName) {
        jQuery("input[name='geo_name']").val('');
        jQuery("input[name='national_id']").val('');
        jQuery("input[name='geo_level']").val('');
    } else {
        var geoLevel = getGeoLevel(geoName);
        var nationalID = getNationalID(geoLevel, geoName);
        jQuery("input[name='geo_name']").val(geoName);
        jQuery("input[name='national_id']").val(nationalID);
        jQuery("input[name='geo_level']").val(geoLevel);
    }
}

/*******************************画面相关************************************/
function getSalesStats()
{
    jQuery.ajaxSettings.async = false;
    var params = [];
    var geoLevel = getGeoLevel(geoName);
    var nationalID = getNationalID(geoLevel, geoName);

    params.push('parameters[geo_name]=' + (!geoName ? geoChain[geoChain.length-1] : geoName));
    params.push('parameters[geo_level]=' + geoLevel);
    params.push('parameters[national_id]=' + nationalID);
    params.push('parameters[year]=' + jQuery("select[name='year']").val());
    params.push('parameters[month]=' + jQuery("select[name='month']").val());

    jQuery.getJSON(nonghuaBaseUrl + '/api/sales?' + params.join('&'), function (json) {
        optionQoQ_sales.legend.data = json.legend;
        optionQoQ_sales.xAxis[0].data = json.xAxis;
        optionQoQ_sales.series = json.yAxis;

        barChartQoQ_sales.setOption(optionQoQ_sales, true);
        jQuery('#myModal').modal('show');
    });
}


function getjurisSalesStats(){
    jQuery.ajaxSettings.async = false;
    var params = [];
    if(jQuery("select[name='juris']").val() == ""){
        alert('区域为必选！'); return false;
    }
    params.push('parameters[distributor]=' + jQuery("select[name='distributor']").val());
    params.push('parameters[juris]=' + jQuery("select[name='juris']").val());
    params.push('parameters[salesman]=' + jQuery("select[name='salesman']").val());
    params.push('parameters[year]=' + jQuery("select[name='year']").val());
    params.push('parameters[month]=' + jQuery("select[name='month']").val());

    jQuery.getJSON(nonghuaBaseUrl + '/api/sales_by_zone?' + params.join('&'), function (json) {
        optionQoQ_sales.legend.data = json.legend;
        optionQoQ_sales.xAxis[0].data = json.xAxis;
        optionQoQ_sales.series = json.yAxis;

        barChartQoQ_sales.setOption(optionQoQ_sales, true);
        jQuery('#myModal').modal('show');
    });
}

/*******************************图表相关************************************/
var optionQoQ_sales = {
    title : {
        text: '销售',
    },
    tooltip : {
        trigger: 'axis',
        formatter: '{c}'
    },
    legend: {
        data:[]
    },
    calculable : false,
    xAxis : [
        {
            type : 'category',
            boundaryGap : false,
            categories : []
        }
    ],
    yAxis : [
        {
            type : 'value'
        }
    ],
    series : []
};

var barChartQoQ_sales = echarts.init(document.getElementById('divQoQ_sales'));

jQuery(function($) {
    initMap("#map_previous", "#map_next");
    $(".content").addClass('map');
    $("#block-system-main").addClass('map');
    $("#map").button("toggle");
    $("#zone-wrapper-div").hide();


    $("#map").click(function (e) {
        e.preventDefault();
        $("#zone-wrapper-div").slideUp();
        $("#map-wrapper-div").slideDown();
        $(".content").addClass('map');
        $(".content").removeClass('zone');
        $("input[name='map_or_zone']").val('map');
        $("#invoiceStat").show();
        $("#jurisinvoiceStat").hide();
    });

    $("#zone").click(function (e) {
        e.preventDefault();
        $("#map-wrapper-div").slideUp();
        $("#zone-wrapper-div").slideDown();
        $(".content").addClass('zone');
        $(".content").removeClass('map');
        $("input[name='map_or_zone']").val('zone');
        $("#invoiceStat").hide();
        $("#jurisinvoiceStat").attr("style","display:block;clear:both");

    });
});
